package com.hoshiicloud.suppplier.service.companyorganization.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hoshiicloud.common.exception.CommonError;
import com.hoshiicloud.common.exception.ServiceException;
import com.hoshiicloud.common.query.OmnipotentParam;
import com.hoshiicloud.common.query.OmnipotentWrapper;
import com.hoshiicloud.goods.entity.goods.Gallery;
import com.hoshiicloud.goods.entity.sku.BaseSku;
import com.hoshiicloud.goods.entity.sku.VendorGoodsSku;
import com.hoshiicloud.goods.entity.spu.BaseGoodsGallery;
import com.hoshiicloud.goods.entity.spu.BaseSpu;
import com.hoshiicloud.goods.param.sku.*;
import com.hoshiicloud.goods.param.spu.BaseSpuAddParam;
import com.hoshiicloud.goods.param.spu.BaseSpuQueryParam;
import com.hoshiicloud.goods.vo.GoodsPropertiesVo;
import com.hoshiicloud.goods.vo.sku.BaseSkuVo;
import com.hoshiicloud.suppplier.feign.GoodsFeignService;
import com.hoshiicloud.suppplier.feign.IdGeneratorService;
import com.hoshiicloud.suppplier.mapper.companyorganization.goodsmanage.GoodsReleaseMapper;
import com.hoshiicloud.suppplier.param.SupplierSkuDetailParam;
import com.hoshiicloud.suppplier.param.SupplierSpuDetailParam;
import com.hoshiicloud.suppplier.param.TenantSupplierGoodsParam;
import com.hoshiicloud.suppplier.service.companyorganization.GoodsReleaseService;
import com.hoshiicloud.suppplier.vo.SupplierSkuDetailVo;
import com.hoshiicloud.suppplier.vo.SupplierSpuDetailVo;
import com.hoshiicloud.suppplier.vo.TenantSupplierGoodsVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;

/**
 * @author linjx on 2019/8/12
 */
@Service
@Slf4j
public class GoodsReleaseServiceImpl implements GoodsReleaseService {

    @Autowired
    private GoodsFeignService goodsFeignService;
    @Autowired
    private GoodsReleaseMapper goodsReleaseMapper;
    @Autowired
    private IdGeneratorService idGeneratorService;

    /**
     * 根据类目id,查询商品发布需要的基础信息
     */
    @Override
    public Map<String, Object> queryBaseMessage(Long categoryId, Map<String, Object> tokenMap) {

        Map<String, Object> resultMap = new HashMap<>();
        Long companyId = Long.valueOf(tokenMap.get("companyId").toString());
        // 类目属性
        List<GoodsPropertiesVo> properties = goodsFeignService.getProperByCateId(categoryId, companyId).getData();
        // 包装单位
        String propertyName = "包装单位";
        List<String> packagings = goodsFeignService.dropdownBox(companyId, propertyName).getData();
        // 销售单位
        String propertyNameSales = "销售单位";
        List<String> sales = goodsFeignService.dropdownBox(companyId, propertyNameSales).getData();
        // 品牌
        List<Map<String, Object>> brands = goodsFeignService.getGoodsBrandsByCateId(categoryId).getData();
        // 商品标签
        List<String> extSpuTagsSelect = Arrays.asList("新鲜", "有机", "无残留");

        // 设置返回信息
        resultMap.put("properties", properties);
        resultMap.put("sales", sales);
        resultMap.put("packagings", packagings);
        resultMap.put("brand", brands);
        resultMap.put("extSpuTagsSelect", extSpuTagsSelect);
        return resultMap;
    }

    /**
     * 租户供应商品发布商品
     */
    @Override
    public Boolean releaseGoods(SupplierSpuDetailParam spuDetailParam) {
        // 保存baseSpu
        BaseSpu baseSpu = this.saveBaseSpu(spuDetailParam);
        // 保存BaseSpu的图片信息
        this.saveBaseGoodsGallery(spuDetailParam);
        // 保存sku相关信息
        String spuNo = baseSpu.getSpuNo();
        String skuCode = "";
        List<SupplierSkuDetailParam> skuDetailParamList = spuDetailParam.getSkuDetailParamList();
        for (SupplierSkuDetailParam skuDetailParam : skuDetailParamList) {
            // 生成sku编码
            String skuNo = this.createSkuCode(spuNo, skuCode);
            // 保存baseSku
            this.saveBaseSku(spuDetailParam, skuDetailParam, skuNo);
            // 保存baseSku的图片信息
            this.saveBaseSkuGallery(spuDetailParam, skuDetailParam);
            // 保存VendorGoodsSku
            this.saveVendorGoodsSku(spuDetailParam, skuDetailParam);
            skuCode = skuNo;
        }
        return true;
    }

    /**
     * 分页查询供应商品发布的商品信息列表
     */
    @Override
    public Page<List<TenantSupplierGoodsVo>> listOfGoods(TenantSupplierGoodsParam supplierGoodsParam) {
        Page page = new Page(supplierGoodsParam.getPageNumber(), supplierGoodsParam.getPageSize());
        List<TenantSupplierGoodsVo> tenantSupplierGoodsVos = goodsReleaseMapper.listOfGoodsPage(page, supplierGoodsParam);
        page.setRecords(tenantSupplierGoodsVos);
        return page;
    }

    /**
     * 查询需要编辑的商品的信息
     */
    @Override
    public TenantSupplierGoodsVo getNeedEditDate(TenantSupplierGoodsParam supplierGoodsParam) {

        TenantSupplierGoodsVo goodsVo = new TenantSupplierGoodsVo();
        VendorGoodsSku vendorSku = goodsFeignService.getVendorGoodsSkuById(supplierGoodsParam.getVendorGoodsSkuId()).getData();

        goodsVo.setBaseSkuId(supplierGoodsParam.getBaseSkuId());
        goodsVo.setBaseSpuId(supplierGoodsParam.getBaseSpuId());
        goodsVo.setVendorGoodsSkuId(supplierGoodsParam.getVendorGoodsSkuId());

        // 条形码
        goodsVo.setBarCode(vendorSku.getBarCode());
        // 箱码
        goodsVo.setPacketCode(vendorSku.getPacketCode());
        // 重量
        goodsVo.setWeight(vendorSku.getWeight());
        // 内件数
        goodsVo.setInnerBoxs(vendorSku.getInnerBoxs());
        // 包装单位
        goodsVo.setPacketUnit(vendorSku.getPacketUnit());
        // 增值税率
        goodsVo.setTaxRate(vendorSku.getTaxRate());
        // 采购类型
        goodsVo.setVendorPoType(vendorSku.getVendorPoType());
        // 包装单位列表
        String propertyName = "包装单位";
        List<String> packagings = goodsFeignService.dropdownBox(supplierGoodsParam.getCompanyId(), propertyName).getData();
        goodsVo.setPacketUnitList(packagings);

        // baseSpu的purchasesType, 用于区分该sku是国内还是跨境
        BaseSpu baseSpu = goodsFeignService.getBaseSpuById(supplierGoodsParam.getBaseSpuId()).getData();
        goodsVo.setPurchaseType(baseSpu.getPurchaseType());

        return goodsVo;
    }

    /**
     * 商品编辑
     */
    @Override
    public Boolean editForGoods(TenantSupplierGoodsParam goodsDto) {

        VendorGoodsSkuUpdateParam param = VendorGoodsSkuUpdateParam.builder()
                // 需要更新的Id
                .id(goodsDto.getVendorGoodsSkuId())
                // 条形码
                .barCode(goodsDto.getBarCode())
                // 箱码
                .packetCode(goodsDto.getPacketCode())
                // 重量
                .weight(goodsDto.getWeight())
                // 内件数
                .innerBoxs(goodsDto.getInnerBoxs())
                // 包装单位
                .packetUnit(goodsDto.getPacketUnit())
                // 增值税率
                .taxRate(goodsDto.getTaxRate())
                // 采购类型
                .vendorPoType(goodsDto.getVendorPoType()).build();

        goodsFeignService.updateVendorGoodsSku(param);

        return true;
    }

    /**
     * 删除商品信息
     */
    @Override
    public Boolean deleteReleaseGoods(TenantSupplierGoodsParam goodsParam) {
        // 删除供应商sku 信息
        Long vendorGoodsSkuId = goodsParam.getVendorGoodsSkuId();
        Boolean data = goodsFeignService.deleteVendorGoodsSkuById(vendorGoodsSkuId).getData();
        return data;
    }

    /**
     * 批量删除商品信息
     */
    @Override
    public Boolean deleteBatchGoods(List<TenantSupplierGoodsParam> goodsParams) {
        // 供应商品商品sku的id集合
        List<Long> vendorGoodsIds = goodsParams.stream().map(TenantSupplierGoodsParam::getVendorGoodsSkuId).collect(Collectors.toList());

        // 删除
        OmnipotentParam<VendorGoodsSku> param = new OmnipotentParam<>();
        List<OmnipotentWrapper> omniList = new ArrayList<>();
        omniList.add(OmnipotentWrapper.setWrapper("in", "id", vendorGoodsIds));
        omniList.add(OmnipotentWrapper.setWrapper("eq", "deleted", 0));

        VendorGoodsSku entityUpdate = new VendorGoodsSku();
        entityUpdate.setDeleted(1);

        param.setWrappers(omniList);
        param.setEntity(entityUpdate);
        goodsFeignService.updateVendorGoodsSkuBatch(param);
        return true;
    }

    /**
     * 查询需要报价的商品的BaseSpu信息
     */
    @Override
    public Page<BaseSpu> ListBaseSpu(TenantSupplierGoodsParam goodsParam) {

        BaseSpuQueryParam queryParam = new BaseSpuQueryParam();
        queryParam.setPageNumber(goodsParam.getPageNumber() + "");
        queryParam.setPageSize(goodsParam.getPageSize() + "");

        queryParam.setCompanyId(goodsParam.getCompanyId());
        queryParam.setPlatformId(goodsParam.getPlatformId());
        queryParam.setStoreId(goodsParam.getStoreId());

        queryParam.setCategoryId(goodsParam.getCategoryId());
        queryParam.setSpuNo(goodsParam.getSpuNo());
        queryParam.setTitle(goodsParam.getTitle());
        queryParam.setDeleted(0);
        queryParam.setDescField("created_time");
        return goodsFeignService.pageBaseSpuForSupplier(queryParam).getData();
    }

    /**
     * 获得需要编辑报价的商品的详细信息, vendorId 供应商的Id
     */
    @Override
    public SupplierSpuDetailVo getNeedEditOfferGoods(TenantSupplierGoodsParam goodsParam) {
        SupplierSpuDetailVo spuVo = new SupplierSpuDetailVo();
        List<SupplierSkuDetailVo> skuVoList = new ArrayList<>();
        Long baseSpuId = goodsParam.getBaseSpuId();
        Long vendorId = goodsParam.getVendorId();

        // 获取baseSpu信息
        BaseSpu baseSpu = goodsFeignService.getBaseSpuById(baseSpuId).getData();

        // 获取该baseSpu的相册信息
        List<BaseGoodsGallery> gallerys = goodsFeignService.listBaseGoodsGalleryBySpuId(baseSpuId).getData();
        List<OmnipotentWrapper> wrapperList = new ArrayList<>();
        wrapperList.add(OmnipotentWrapper.setWrapper("in", "id", gallerys.stream().map(BaseGoodsGallery::getGalleryId).collect(Collectors.toList())));
        List<String> galleryList = goodsFeignService.queryGalleryBatch(wrapperList).getData().stream().map(Gallery::getImgUrl).collect(Collectors.toList());

        // 获得baseSku, vendorGoodsSku数据回填
        this.skuAndVendorBackfillDate(baseSpuId, vendorId, skuVoList);

        // 放着， 后面需要查询品牌所属国
        //GoodsBrand goodsBrand = lesseeGoodsFeignService.getGoodsBrandById(baseSpu.getBrandId()).getData();

        spuVo.setBaseSpuId(baseSpu.getId());
        spuVo.setCategoryContext(baseSpu.getCategoryContext());
        spuVo.setCompanyId(baseSpu.getCompanyId());
        spuVo.setPlatformId(baseSpu.getPlatformId());
        spuVo.setStoreId(baseSpu.getStoreId());
        spuVo.setTitle(baseSpu.getTitle());
        spuVo.setSpuNo(baseSpu.getSpuNo());
        spuVo.setBrandId(baseSpu.getBrandId());
        spuVo.setProductType(baseSpu.getProductType());
        spuVo.setProductType(baseSpu.getPurchaseType());
        spuVo.setExtendProperty(baseSpu.getExtendProperty());
        spuVo.setImageArr(galleryList);
        spuVo.setSkuDetailVos(skuVoList);
        return spuVo;
    }

    /**
     * 编辑需要报价的商品
     */
    @Override
    public Boolean editOfferGoods(SupplierSpuDetailParam spuDetailParam) {

        List<SupplierSkuDetailParam> skuDetailParamList = spuDetailParam.getSkuDetailParamList();
        // 如果该供应商未报价过该商品， 那么我会回传给前端 vendorGoodsSkuId 为0， 通过这个判断是更新报价还是为该供应商添加新的报价商品
        long idsSum = skuDetailParamList.stream().mapToLong(SupplierSkuDetailParam::getVendorGoodsSkuId).sum();
        if (idsSum == 0) {
            // idsSum == 0, 说明该供应商未供价过该商品，为该供应商品，添加新的商品供价
            skuDetailParamList.stream().forEach(skuDetailParam -> {
                this.saveVendorGoodsSku(spuDetailParam, skuDetailParam);
            });
        } else {
            // 更新已供价的商品信息
            skuDetailParamList.stream().forEach(skuDetailParam -> {
                this.updateVendorGoodsSku(spuDetailParam, skuDetailParam);
            });
        }
        return true;
    }


    // ============================租户供应商品发布商品=======================================

    private BaseSpu saveBaseSpu(SupplierSpuDetailParam spuDetailParam) {
        BaseSpuAddParam baseSpuAddParam = this.setBaseSpuAdd(spuDetailParam);
        // 设置categoryContext
        String categoryIdStr = StringUtils.join(spuDetailParam.getCategoryArr(), "\',\'");
        String categoryContextQueryStr = "\'" + categoryIdStr + "\'";
        String categoryContext = goodsFeignService.getCategoryContext(categoryContextQueryStr).getData();
        baseSpuAddParam.setCategoryContext(categoryContext);
        BaseSpu baseSpu = goodsFeignService.saveBaseSpu(baseSpuAddParam).getData();
        spuDetailParam.setBaseSpuId(baseSpu.getId());
        return baseSpu;
    }

    private void saveBaseGoodsGallery(SupplierSpuDetailParam spuDetailParam) {
        List<Gallery> galleryList = new ArrayList<>();
        List<BaseGoodsGallery> baseGoodsGalleryList = new ArrayList<>();

        String imagesStr = spuDetailParam.getDefaultImage();
        String[] images = imagesStr.split(",");

        // 保存相册信息
        for (String image : images) {
            Long galleryId = this.getId();
            Gallery gallery = new Gallery();
            gallery.setId(galleryId);
            gallery.setImgUrl(image);
            gallery.setCreateTime(LocalDateTime.now());
            galleryList.add(gallery);
        }
        goodsFeignService.saveGalleryBath(galleryList);

        // 保存BaseSpu与 相册的关联信息
        for (Gallery gallery : galleryList) {
            Long baseGoodsGalleryId = this.getId();
            BaseGoodsGallery baseGoodsGallery = new BaseGoodsGallery();
            baseGoodsGallery.setId(baseGoodsGalleryId);
            baseGoodsGallery.setGoodsId(spuDetailParam.getBaseSpuId());
            baseGoodsGallery.setGalleryId(gallery.getId());
            baseGoodsGallery.setCreateTime(gallery.getCreateTime());
            baseGoodsGalleryList.add(baseGoodsGallery);
        }
        goodsFeignService.saveBaseGoodsGalleryBatch(baseGoodsGalleryList);

    }

    private void saveBaseSku(SupplierSpuDetailParam spuDetailParam, SupplierSkuDetailParam skuDetailParam, String skuNo) {
        BaseSkuAddParam param = this.setBaseSkuAdd(spuDetailParam, skuDetailParam);
        param.setSkuNo(skuNo);
        BaseSku baseSku = goodsFeignService.saveBaseSku(param).getData();
        skuDetailParam.setBaseSkuId(baseSku.getId());
    }

    private void saveVendorGoodsSku(SupplierSpuDetailParam spuDetailParam, SupplierSkuDetailParam skuDetailParam) {
        VendorGoodsSkuAddParam vendorGoodsSku = this.setVendorGoodsSkuAdd(spuDetailParam, skuDetailParam);
        goodsFeignService.saveVendorGoodsSku(vendorGoodsSku);
    }

    private void saveBaseSkuGallery(SupplierSpuDetailParam spuDetailParam, SupplierSkuDetailParam skuDetailParam) {
        BaseSkuGalleryAddParam addParam = new BaseSkuGalleryAddParam();
        addParam.setSkuId(skuDetailParam.getBaseSkuId());
        addParam.setImageType(1);
        addParam.setImage(skuDetailParam.getSkuImage());
        addParam.setCreatedBy(spuDetailParam.getCreateBy());
        goodsFeignService.saveBaseSkuGallery(addParam);
    }

    // ============================更新=======================================

    private void updateVendorGoodsSku(SupplierSpuDetailParam spuDetailParam, SupplierSkuDetailParam skuDetailParam) {
        VendorGoodsSkuUpdateParam vendorGoodsSkuUpdateParam = this.setVendorGoodsSkuUpdate(spuDetailParam, skuDetailParam);
        goodsFeignService.updateVendorGoodsSku(vendorGoodsSkuUpdateParam);
    }

    // ============================spu/sku编码生成以及ID生成=======================================

    /**
     * spu编码生成 类目编码+商品类型+年月日（各取2位）+秒数（创建时间时分秒转换成秒数）+7位随机数
     */
    private String creteSpuCode(String categoryCode, Integer purchaseType, LocalDateTime createTime) {
        StringBuffer spuCode = new StringBuffer(categoryCode.replace(",", ""));
        spuCode.append(purchaseType);
        spuCode.append(DateTimeFormatter.ofPattern("yyMMdd").format(createTime));
        spuCode.append(createTime.toLocalTime().toSecondOfDay());
        spuCode.append(ThreadLocalRandom.current().nextInt(1000000, 9999999));
        return spuCode.toString();
    }

    /**
     * sku编码生成 SPU_CODE+序号（最大99，从01开始）
     */
    private String createSkuCode(String spuNo, String skuNo) {
        if (StringUtils.isBlank(skuNo)) {
            return spuNo + "01";
        } else {
            // 截取skuNo后两位
            String numStr = skuNo.substring(spuNo.length() - 2);
            // 自增1
            long num = Long.parseLong(numStr);
            String lastNo = String.format("%02d", ++num);
            // 截取原先skuNo 除了后两位的前面的位数
            String baseNo = spuNo.substring(0, spuNo.length() - 2);
            return baseNo + lastNo;
        }
    }

    /**
     * 生成一个Id 并且返回
     */
    private Long getId() {
        String id = idGeneratorService.queryGeneratorId();
        if (StrUtil.isBlank(id)) {
            throw new ServiceException(CommonError.error("主键ID生成失败"));
        }
        return Long.parseLong(id);
    }

    // ====================================商品报价===================================

    private void skuAndVendorBackfillDate(Long baseSpuId, Long vendorId, List<SupplierSkuDetailVo> skuVoList) {

        // 通过baseSpuId查询获取该baseSpu下的BaseSku信息
        SkuBaseListParam param = new SkuBaseListParam();
        param.setSpuId(baseSpuId);
        param.setDeleted(0);
        List<BaseSkuVo> baseSkuList = goodsFeignService.listBaseSkuByParam(param).getData();

        // 根据BaseSpuId 和  vendorId 查询供应商Sku表，判断该供应商是否报价过该商品
        List<OmnipotentWrapper> vendorWrapperList = new ArrayList<>();
        vendorWrapperList.add(OmnipotentWrapper.setWrapper("eq", "spu_id", baseSpuId));
        vendorWrapperList.add(OmnipotentWrapper.setWrapper("eq", "vendor_id", vendorId));
        vendorWrapperList.add(OmnipotentWrapper.setWrapper("eq", "deleted", 0));
        List<VendorGoodsSku> vendorList = goodsFeignService.listVendorGoodsSku(vendorWrapperList).getData();

        // 遍历baseSku并为skuVo赋值
        baseSkuList.stream().forEach(baseSku -> {
            SupplierSkuDetailVo skuVo = new SupplierSkuDetailVo();
            skuVo.setBaseSkuId(baseSku.getId());
            skuVo.setExtendSpec(baseSku.getExtendSpec());
            skuVo.setSkuNo(baseSku.getSkuNo());
            skuVo.setSalesUnit(baseSku.getSalesUnit());
            skuVo.setSkuImage(goodsFeignService.listBaseSkuGalleryByBaseSkuId(baseSku.getId()).getData().get(0).getImage());
            skuVo.setVendorGoodsSkuId(0L);
            skuVo.setBarCode("");
            skuVo.setPacketCode("");
            skuVo.setPacketUnit("");
            skuVo.setWeight(BigDecimal.ZERO);
            skuVo.setInnerBoxs(0);
            skuVo.setTaxUnitprice(BigDecimal.ZERO);
            skuVo.setUnitprice(BigDecimal.ZERO);
            skuVo.setTaxRate(BigDecimal.ZERO);
            skuVo.setVendorPoType(0);

            if (!vendorList.isEmpty()) {
                VendorGoodsSku vendorSku = vendorList.stream().filter(s -> s.getSkuId().longValue() == baseSku.getId().longValue()).collect(Collectors.toList()).get(0);
                skuVo.setVendorGoodsSkuId(vendorSku.getId());
                skuVo.setBarCode(vendorSku.getBarCode());
                skuVo.setPacketCode(vendorSku.getPacketCode());
                skuVo.setPacketUnit(vendorSku.getPacketUnit());
                skuVo.setWeight(vendorSku.getWeight());
                skuVo.setInnerBoxs(vendorSku.getInnerBoxs());
                skuVo.setTaxUnitprice(vendorSku.getTaxUnitprice());
                skuVo.setUnitprice(vendorSku.getUnitPrice());
                skuVo.setTaxRate(vendorSku.getTaxRate());
                skuVo.setVendorPoType(vendorSku.getVendorPoType());
            }
            skuVoList.add(skuVo);
        });
    }

    // ====================================一些字段的设置===================================

    /**
     * 设置添加BaseSpu需要保存的值
     */
    private BaseSpuAddParam setBaseSpuAdd(SupplierSpuDetailParam spuDetailParam) {

        // 商品编码
        String spuNo = this.creteSpuCode(StringUtils.join(spuDetailParam.getCategoryArr()), spuDetailParam.getPurchaseType(), LocalDateTime.now());

        return BaseSpuAddParam.builder()
                // 租户Id
                .companyId(spuDetailParam.getCompanyId())
                // 平台Id
                .platformId(spuDetailParam.getPlatformId())
                // 店铺Id
                .storeId(spuDetailParam.getStoreId())
                // 创建人
                .createdBy(spuDetailParam.getCreateBy())
                // 商品编码
                .spuNo(spuNo)
                // 商品名称
                .title(spuDetailParam.getTitle())
                // 商品类目Id
                .categoryId(spuDetailParam.getCategoryArr()[spuDetailParam.getCategoryArr().length - 1])
                // 类目描述
                .categoryDescribe(StringUtils.join(spuDetailParam.getCategoryArr(), ","))
                // 品牌
                .brandId(spuDetailParam.getBrandId())
                // 商品类型
                .productType(spuDetailParam.getProductType())
                // 采购类型
                .purchaseType(spuDetailParam.getPurchaseType())
                // 属性
                .extendProperty(spuDetailParam.getExtendProperty())
                // 默认图片
                .defaultImage(spuDetailParam.getDefaultImage().split(",")[0])
                // 1-共有 2-私有
                .published(1)
                // 上下架状态
                .status(1).build();
    }

    /**
     * 设置 BaseSku 需要保存的值
     */
    private BaseSkuAddParam setBaseSkuAdd(SupplierSpuDetailParam spuDetailParam, SupplierSkuDetailParam skuDetailParam) {

        BaseSkuAddParam baseSku = new BaseSkuAddParam();

        return BaseSkuAddParam.builder()
                // 租户Id
                .companyId(spuDetailParam.getCompanyId())
                // 平台Id
                .platformId(spuDetailParam.getPlatformId())
                // 店铺Id
                .storeId(spuDetailParam.getStoreId())
                // 创建人
                .createdBy(spuDetailParam.getCreateBy())
                // BaseSpuId
                .spuId(spuDetailParam.getBaseSpuId())
                // 商品标题
                .skuTitle(spuDetailParam.getTitle())
                // 销售单位（*）
                .salesUnit(skuDetailParam.getSalesUnit())
                // 条形码
                .barCode(skuDetailParam.getBarCode())
                // 箱码
                .packetCode(skuDetailParam.getPacketCode())
                // 规格
                .extendSpec(skuDetailParam.getExtendSpec())
                // 是否允许分销 0-不允许分销 1-允许分销
                .distributorStatu(skuDetailParam.getDistributorStatu())
                .isStored(0)
                .status(1).build();
    }


    /**
     * 设置供应商sku需要保存的值
     */
    private VendorGoodsSkuAddParam setVendorGoodsSkuAdd(SupplierSpuDetailParam spuDetailParam, SupplierSkuDetailParam skuDetailParam) {

        return VendorGoodsSkuAddParam.builder()
                // 租户Id
                .companyId(spuDetailParam.getCompanyId())
                // 平台Id
                .platformId(spuDetailParam.getPlatformId())
                // 店铺Id
                .storeId(spuDetailParam.getStoreId())
                // 创建人
                .createdBy(spuDetailParam.getCreateBy())
                // skuId
                .skuId(skuDetailParam.getBaseSkuId())
                // spuId
                .spuId(spuDetailParam.getBaseSpuId())
                // 条形码
                .barCode(skuDetailParam.getBarCode())
                // 箱码
                .packetCode(skuDetailParam.getPacketCode())
                // 包装单位
                .packetUnit(skuDetailParam.getPacketUnit())
                // 内件数
                .innerBoxs(skuDetailParam.getInnerBoxs())
                // 商品重量
                .weight(skuDetailParam.getWeight())
                // 供价（不含税）
                .unitPrice(skuDetailParam.getUnitprice())
                // 供价（含税）
                .taxUnitprice(skuDetailParam.getTaxUnitprice())
                // 增值税率
                .taxRate(skuDetailParam.getTaxRate())
                // 采购类型
                .vendorPoType(skuDetailParam.getVendorPoType())
                // 供应商Id
                .vendorId(skuDetailParam.getVendorId()).build();

    }

    private VendorGoodsSkuUpdateParam setVendorGoodsSkuUpdate(SupplierSpuDetailParam spuDetailParam, SupplierSkuDetailParam skuDetailParam) {

        return VendorGoodsSkuUpdateParam.builder()
                // 设置需要更新的Id
                .id(skuDetailParam.getVendorGoodsSkuId())
                // 更新人
                .updatedBy(spuDetailParam.getUpdateBy())
                // 条形码
                .barCode(skuDetailParam.getBarCode())
                // 箱码
                .packetCode(skuDetailParam.getPacketCode())
                // 包装单位
                .packetUnit(skuDetailParam.getPacketUnit())
                // 内件数
                .innerBoxs(skuDetailParam.getInnerBoxs())
                // 商品重量
                .weight(skuDetailParam.getWeight())
                // 供价（不含税）
                .unitPrice(skuDetailParam.getUnitprice())
                // 供价（含税）
                .taxUnitprice(skuDetailParam.getTaxUnitprice())
                // 增值税率
                .taxRate(skuDetailParam.getTaxRate())
                // 采购类型
                .vendorPoType(skuDetailParam.getVendorPoType()).build();
    }

}
